<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// 创建连接
$connect = mysqli_connect($servername, $username, $password, $dbname);

//检查连接
if (!$connect) {
    die("连接失败" . mysqli_connect_error());
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES (?, ?, ?)";
// 为 mysqli_stmt_prepare() 初始化 statement 对象
$stmt = mysqli_stmt_init($connect);
//预处理语句
if (mysqli_stmt_prepare($stmt, $sql)) {
    // 绑定参数
    mysqli_stmt_bind_param($stmt, 'sss', $firstname, $lastname, $email);

    // 设置参数并执行
    $firstname = 'aotian';
    $lastname = 'long';
    $email = 'aotian@email.com';
    mysqli_stmt_execute($stmt);

    $firstname = 'ritian';
    $lastname = 'zhao';
    $email = 'ritian@email.com';
    mysqli_stmt_execute($stmt);

    $firstname = 'tangzhu';
    $lastname = 'murong';
    $email = 'tangzhu@email.com';
    mysqli_stmt_execute($stmt);

    echo '插入完成';
}
//关闭连接
mysqli_close($connect);
?>